<?php slot('studyGroupsNav', 'active') ?>
<div id="wrapper" class="courses">
	<?php include_partial('global/systemMessages', array('form' => $form)) ?>
	
	<div id="content">
		<div id="main">
			<div class="main-heading">
				<h1><?php echo $form->isNew() ? 'Create a Group' : 'Edit '. $form['name']->getValue() ?></h1>
			</div>
			<?php include_partial('subnav', array('group_id' => $form['id']->getValue(), 'current' => 'Settings')) ?>
			<form class="settings" action="<?php echo url_for('groups/update') ?>" method="post">
				<h4>
					<span>General Group Settings</span>
				</h4>
				<fieldset>
					<label>Group Name</label>
					<?php echo $form['name']->render(array('class' => 'input-text')) ?>
					<label>Group Description</label> 
					<?php echo $form['description']->render(array('rows' => '10', 'cols' => '48'))?>
				</fieldset>
				<h4>
					<span>This Group is for...</span>
				</h4>
				<fieldset>
					<label>Course</label>
					<?php echo $form['course_ids']->render() ?>
					<p style="font-size:10px;">
						Can't find the Course you want? <a id='create_course_btn' href="#">Create it first.</a>
					</p>
				</fieldset>
				<?php if(isset($member_forms)): ?>
					<h4>
						<span>User Permissions</span>
					</h4>
					<fieldset>					
							<?php foreach($member_forms as $member_form): ?>
								<div style="clear: left; float: left; width: 150px;">
									<?php echo $member_form['role']->renderLabel() ?>
								</div>
								<span style="float: left;">
									<?php echo $member_form['role']->render() ?>
								</span>
								<?php echo $member_form['send_invites']->render(array('style' => 'float: left;')) ?>
								<?php echo $member_form['send_invites']->renderLabel(null, array('style' => 'float: left; padding-left: 5px;')) ?>	
								<?php echo $member_form->renderHiddenFields() ?>			
							<?php endforeach ?>
	    			</fieldset>				
				<?php endif ?>
				<h4>
					<span>Group Privacy Settings</span>
				</h4>
				<fieldset>
					<label>Who can view this Group in the Groups List and request membership?</label>
					<?php echo $form['visibility']->render() ?>
					<!--<label>Make all Group content...</label>
					<ul class="radios">
						<li><label><input type="radio" name="group_type" value="public" />Public</label></li>
						<li><label><input type="radio" name="group_type" value="private" />Private</label></li>
					</ul>-->
							<!--<label>Some other privacy option?</label>
					<ul class="radios">
						<li><label><input type="radio" />Yes</label></li>
						<li><label><input type="radio" />No</label></li>
					</ul>-->
				</fieldset>
				<fieldset class="controls">
					<?php echo $form->renderHiddenFields() ?>
					<input type="submit" value="<?php echo $form->isNew() ? 'Create Group' : 'Save Changes' ?>" name="submit">
					<?php echo link_to('Cancel', 'groups/index') ?>
				</fieldset>
			</form>
		</div>
		<!-- MAIN -->
		<div id="sidebar">
			<?php if(!$form->isNew()): ?>
				<?php include_component('group_members', 'list', array('group_id' => $form['id']->getValue())) ?>
			<?php endif ?>
		</div>
	</div>
</div>

<div id="create_course_dialog" style="display: none;" >
<div id='background' style=" z-index: 50; opacity:0.4; filter:alpha(opacity=40); background-color: #333333; position:absolute; top: 0px; left: 0px; width: 100%; height: 1600px;"></div>

	<div id="close_course_dialog_window" style="z-index: 80; position:absolute; top: 600px; left: 150px; border: solid black 2px; background-color: #FFFFFF">
	
		<div id="close_btn" style="background-color: #DFDFDF; cursor: pointer; position: absolute; right: 0px; top: 0px; padding:5px; border: black 1px solid; font-size: 20px">
			X
		</div>
		
		<div id="create_course_dialog_inner" style="margin-top: 20px;">
		
		
		</div>
	
	</div>

</div>


<script>

function bindShowDialog()
{

	
	$('#create_course_btn').click(function(){
		$.get('<?php echo url_for('courses/new')?>',
			{
				redirect: '<?php echo url_for('groups/edit').'/id/'.$form['id']->getValue()?>'
			},
			showDialog);
		
		return false;
		});
	
}

function showDialog(data)
{


	//show dialog
	$('#create_course_dialog').show();

	//insert create course form
	$('#create_course_dialog_inner').html(data);

	//refocus window
}




function bindCloseDialog()
{

	$('#close_btn').click(function(){
		closeDialog();
		});
	
}


function closeDialog(){

	$('#create_course_dialog').hide();		
	
}

$(document).ready(
		function(){
		bindShowDialog();
		bindCloseDialog();	
	});
</script>